/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lvyh.lightframe.job.admin.common;


import org.quartz.simpl.SimpleThreadPool;

/**
 * @author lvyh 2021/05/16.
 */
public class JobInternalContext {
    /**
     * Number of scheduler threads
     */
    private static int scheduleThreadCount;

    /**
     * Scheduling thread object
     */
    private static SimpleThreadPool threadPool;

    /**
     * Percentage of idle threads
     */
    private volatile static int scheduleIdleThreadPercent;

    /**
     * Scheduler resource check delay time
     */
    private volatile static long jobCheckWaitTime;

    private static int scheduleMaxTimeout;

    private static int scheduleMaxRetryTimes;

    public static int getScheduleMaxRetryTimes() {
        return scheduleMaxRetryTimes;
    }

    public static void setScheduleMaxRetryTimes(int scheduleMaxRetryTimes) {
        if (scheduleMaxRetryTimes < 0) {
            scheduleMaxRetryTimes = 10;
        }
        JobInternalContext.scheduleMaxRetryTimes = scheduleMaxRetryTimes;
    }

    public static int getScheduleMaxTimeout() {
        return scheduleMaxTimeout;
    }

    public static void setScheduleMaxTimeout(int scheduleMaxTimeout) {
        if (scheduleMaxTimeout <= 0) {
            scheduleMaxTimeout = 60000;
        }
        JobInternalContext.scheduleMaxTimeout = scheduleMaxTimeout;
    }

    public static int getScheduleThreadCount() {
        return scheduleThreadCount;
    }

    public static void setScheduleThreadCount(int scheduleThreadCount) {
        JobInternalContext.scheduleThreadCount = scheduleThreadCount;
    }

    public static SimpleThreadPool getThreadPool() {
        return threadPool;
    }

    public static void setThreadPool(SimpleThreadPool threadPool) {
        JobInternalContext.threadPool = threadPool;
    }

    public static int getScheduleIdleThreadPercent() {
        return scheduleIdleThreadPercent;
    }

    public static void setScheduleIdleThreadPercent(int scheduleIdleThreadPercent) {
        if (scheduleIdleThreadPercent > 100 || scheduleIdleThreadPercent < 0) {
            scheduleIdleThreadPercent = 25;
        }

        JobInternalContext.scheduleIdleThreadPercent = scheduleIdleThreadPercent;
    }

    public static long getJobCheckWaitTime() {
        return jobCheckWaitTime;
    }

    public static void setJobCheckWaitTime(long jobCheckWaitTime) {
        JobInternalContext.jobCheckWaitTime = jobCheckWaitTime;
    }
}
